<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.20"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>The small3d library: Sound.hpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="customdoxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="logo_s.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">The small3d library
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.20 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_1bbf6a76ff8eaf46cd48acba40dce3d2.html">small3d</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Sound.hpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_sound_8hpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160; </div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="preprocessor">#pragma once</span></div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160; </div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="preprocessor">#include &lt;unordered_map&gt;</span></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160; </div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="preprocessor">#if defined(__ANDROID__)</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="preprocessor">#include &lt;aaudio/AAudio.h&gt;</span></div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="preprocessor">#elif defined(SMALL3D_IOS)</span></div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="preprocessor">#include &lt;OpenAL/al.h&gt;</span></div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="preprocessor">#include &lt;OpenAL/alc.h&gt;</span></div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;<span class="preprocessor">#else</span></div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="preprocessor">#include &lt;portaudio.h&gt;</span></div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160; </div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="preprocessor">#include &lt;vector&gt;</span></div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="preprocessor">#include &lt;string&gt;</span></div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160; </div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespacesmall3d.html">small3d</a> {</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160; </div>
<div class="line"><a name="l00033"></a><span class="lineno"><a class="line" href="classsmall3d_1_1_sound.html">   33</a></span>&#160;  <span class="keyword">class </span><a class="code" href="classsmall3d_1_1_sound.html">Sound</a> {</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;    </div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;  <span class="keyword">private</span>:</div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160; </div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;    <span class="keyword">struct </span>SoundData {</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;      <span class="keywordtype">int</span> channels = 0;</div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;      <span class="keywordtype">int</span> rate = 0;</div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;      <span class="keywordtype">long</span> samples = 0;</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;      <span class="keywordtype">long</span> size = 0;</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;      <span class="keywordtype">double</span> duration = 0;</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;      <span class="keywordtype">double</span> startTime = 0;</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;      <span class="keywordtype">bool</span> repeat = <span class="keyword">false</span>;</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;      <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> currentFrame = 0;</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;      std::vector&lt;char&gt; data;</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;    };</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160; </div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;    SoundData soundData;</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;    </div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;<span class="preprocessor">#if !defined(__ANDROID__) &amp;&amp; !defined(SMALL3D_IOS)</span></div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;    PaStream *stream;</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;<span class="preprocessor">#elif defined(__ANDROID__)</span></div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;    AAudioStreamBuilder *streamBuilder;</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;    AAudioStream *stream;</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;<span class="preprocessor">#elif defined(SMALL3D_IOS)</span></div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;<span class="keyword">static</span> ALCdevice *openalDevice;</div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;<span class="keyword">static</span> ALCcontext *openalContext;</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;    ALuint openalSource;</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;    ALuint openalBuffer;</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160; </div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">bool</span> noOutputDevice;</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160; </div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> numInstances;</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;    </div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;<span class="preprocessor">#if !defined(SMALL3D_IOS) &amp;&amp; !defined(__ANDROID__)</span></div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;    <span class="keyword">static</span> PaDeviceIndex defaultOutput;</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;    <span class="keyword">static</span> <span class="keywordtype">int</span> audioCallback(<span class="keyword">const</span> <span class="keywordtype">void</span> *inputBuffer, <span class="keywordtype">void</span> *outputBuffer,</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;                 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> framesPerBuffer,</div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;                 <span class="keyword">const</span> PaStreamCallbackTimeInfo *timeInfo,</div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;                 PaStreamCallbackFlags statusFlags,</div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;                 <span class="keywordtype">void</span> *userData);</div>
<div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;<span class="preprocessor">#elif defined(__ANDROID__)</span></div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;    <span class="keyword">static</span> aaudio_data_callback_result_t audioCallback (</div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;      AAudioStream *stream,</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;      <span class="keywordtype">void</span> *userData,</div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;      <span class="keywordtype">void</span> *audioData,</div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;      int32_t numFrames);</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160; </div>
<div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;    <span class="keywordtype">void</span> load(<span class="keyword">const</span> std::string soundFilePath);</div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;    <span class="keywordtype">void</span> openStream();</div>
<div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160; </div>
<div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;  <span class="keyword">public</span>:</div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;    <a class="code" href="classsmall3d_1_1_sound.html#a3bf41af25f517dc9489d795402b18219">Sound</a>();</div>
<div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160; </div>
<div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;    <a class="code" href="classsmall3d_1_1_sound.html#a3bf41af25f517dc9489d795402b18219">Sound</a>(<span class="keyword">const</span> std::string soundFilePath);</div>
<div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160; </div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;    <a class="code" href="classsmall3d_1_1_sound.html#ad099eea274cd698016aa32e40abc1b00">~Sound</a>();</div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160; </div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;    <span class="keywordtype">void</span> <a class="code" href="classsmall3d_1_1_sound.html#a24b61d06b9c695f5686846fb59c78676">play</a>(<span class="keyword">const</span> <span class="keywordtype">bool</span> repeat=<span class="keyword">false</span>);</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160; </div>
<div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;    <span class="keywordtype">void</span> <a class="code" href="classsmall3d_1_1_sound.html#a3b239ef468eae9e89c48351127b329f3">stop</a>();</div>
<div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160; </div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;    <a class="code" href="classsmall3d_1_1_sound.html#a3bf41af25f517dc9489d795402b18219">Sound</a>(<span class="keyword">const</span> <a class="code" href="classsmall3d_1_1_sound.html">Sound</a>&amp; other) noexcept;</div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160; </div>
<div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;    <a class="code" href="classsmall3d_1_1_sound.html#a3bf41af25f517dc9489d795402b18219">Sound</a>(<span class="keyword">const</span> <a class="code" href="classsmall3d_1_1_sound.html">Sound</a>&amp;&amp; other) noexcept;</div>
<div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160; </div>
<div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;    <a class="code" href="classsmall3d_1_1_sound.html">Sound</a>&amp; <a class="code" href="classsmall3d_1_1_sound.html#a018a0b62cd18522e106dee4882e09538">operator=</a>(<span class="keyword">const</span> <a class="code" href="classsmall3d_1_1_sound.html">Sound</a>&amp; other) noexcept;</div>
<div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160; </div>
<div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;    <a class="code" href="classsmall3d_1_1_sound.html">Sound</a>&amp; <a class="code" href="classsmall3d_1_1_sound.html#a018a0b62cd18522e106dee4882e09538">operator=</a>(<span class="keyword">const</span> <a class="code" href="classsmall3d_1_1_sound.html">Sound</a>&amp;&amp; other) noexcept;</div>
<div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;    </div>
<div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;  };</div>
<div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160; </div>
<div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;}</div>
</div><!-- fragment --></div><!-- contents -->
<div class="ttc" id="aclasssmall3d_1_1_sound_html_a018a0b62cd18522e106dee4882e09538"><div class="ttname"><a href="classsmall3d_1_1_sound.html#a018a0b62cd18522e106dee4882e09538">small3d::Sound::operator=</a></div><div class="ttdeci">Sound &amp; operator=(const Sound &amp;other) noexcept</div><div class="ttdoc">Copy assignment.</div><div class="ttdef"><b>Definition:</b> Sound.cpp:525</div></div>
<div class="ttc" id="aclasssmall3d_1_1_sound_html"><div class="ttname"><a href="classsmall3d_1_1_sound.html">small3d::Sound</a></div><div class="ttdoc">Class that loads and plays a sound from an ogg file.</div><div class="ttdef"><b>Definition:</b> Sound.hpp:33</div></div>
<div class="ttc" id="aclasssmall3d_1_1_sound_html_a24b61d06b9c695f5686846fb59c78676"><div class="ttname"><a href="classsmall3d_1_1_sound.html#a24b61d06b9c695f5686846fb59c78676">small3d::Sound::play</a></div><div class="ttdeci">void play(const bool repeat=false)</div><div class="ttdoc">Play the sound.</div><div class="ttdef"><b>Definition:</b> Sound.cpp:440</div></div>
<div class="ttc" id="aclasssmall3d_1_1_sound_html_ad099eea274cd698016aa32e40abc1b00"><div class="ttname"><a href="classsmall3d_1_1_sound.html#ad099eea274cd698016aa32e40abc1b00">small3d::Sound::~Sound</a></div><div class="ttdeci">~Sound()</div><div class="ttdoc">Destructor.</div><div class="ttdef"><b>Definition:</b> Sound.cpp:258</div></div>
<div class="ttc" id="anamespacesmall3d_html"><div class="ttname"><a href="namespacesmall3d.html">small3d</a></div><div class="ttdef"><b>Definition:</b> BoundingBoxSet.hpp:19</div></div>
<div class="ttc" id="aclasssmall3d_1_1_sound_html_a3b239ef468eae9e89c48351127b329f3"><div class="ttname"><a href="classsmall3d_1_1_sound.html#a3b239ef468eae9e89c48351127b329f3">small3d::Sound::stop</a></div><div class="ttdeci">void stop()</div><div class="ttdoc">Stop playing the sound.</div><div class="ttdef"><b>Definition:</b> Sound.cpp:481</div></div>
<div class="ttc" id="aclasssmall3d_1_1_sound_html_a3bf41af25f517dc9489d795402b18219"><div class="ttname"><a href="classsmall3d_1_1_sound.html#a3bf41af25f517dc9489d795402b18219">small3d::Sound::Sound</a></div><div class="ttdeci">Sound()</div><div class="ttdoc">Default constructor.</div><div class="ttdef"><b>Definition:</b> Sound.cpp:205</div></div>
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="http://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.8.20
</small></address>
</body>
</html>
